package com.isoftstone.app.controller.index;


import com.isoftstone.bank.controller.base.BaseController;
import com.isoftstone.common.Tidings;
import com.isoftstone.util.BocHttpUtil;
import com.isoftstone.util.Const;
import com.isoftstone.util.PropertiesUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@Controller
public class IndexController extends BaseController {

    @RequestMapping("app/index")
    public void appindex(HttpServletRequest request , HttpServletResponse response) throws IOException {
        
        String appindexurl = PropertiesUtils.getProperties("appindex");

        System.out.println("serverAccessToken====="+this.getSession().getAttribute("accessToken"));

        String url = appindexurl+"?accessToken="+this.getSession().getAttribute("accessToken")+"&userid="+this.getSession().getAttribute("userid");
        
        response.sendRedirect(url);
    }

    /**
     * 查询中银开放平台用户信息
     * @param request
     * @return
     * @throws IOException
     */

    @RequestMapping(value ="app/admin/user/userinfo" , method = RequestMethod.POST)
    @ResponseBody
    public Object getuserinfo(HttpServletRequest request )  {

        Tidings<Map<String, String>> tidings = new Tidings<Map<String, String>>();

        try {

            Map<String, String> userInfo = BocHttpUtil.queryUserInfo(request);
            tidings.setT(userInfo);
            tidings.setStatus(Const.SUCCESS);
            tidings.setStatus("成功");
        }catch (Exception ex){
            ex.printStackTrace();
            tidings.setStatus(Const.ERROR);
            tidings.setStatus(ex.getMessage());
        }

        return tidings;
    }
}
